#ifndef __ZAP2IT_STUFF
#define __ZAP2IT_STUFF

/*
 *   This file is part of ed_pvr.
 *
 *   ed_pvr is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   ed_pvr is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with ed_pvr.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifdef __cplusplus
    extern "C" {
#endif

#include <stdint.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <pthread.h>
#include "timers.h"

#define ZAP2IT_MAX_STRLEN		257
#define ZAP2IT_MAX_EPG_DAYS		11

struct _zap2it_single_epg_entry_s {
//	uint8_t		is_first;
    int64_t		start_epoch;
    int64_t		end_epoch;
	double		duration;
	uint8_t 	is_new;
	uint32_t	genre_mask;

    char		prg_title[ZAP2IT_MAX_STRLEN];
    char		ep_title[ZAP2IT_MAX_STRLEN];
    char		desc[ZAP2IT_MAX_STRLEN];
	char 		tmsid[ZAP2IT_MAX_STRLEN];
	struct 		_zap2it_single_epg_entry_s *next;
};
typedef struct _zap2it_single_epg_entry_s zap2it_single_epg_entry_s;

struct _zap2it_epg_channel_s {
	uint64_t	channel_num;
	uint32_t 	channel_count;
    char		icon_path[ZAP2IT_MAX_STRLEN];
    char		channel_name[ZAP2IT_MAX_STRLEN];
	uint8_t 	hd_flag;

	uint64_t	epg_count;
	zap2it_single_epg_entry_s 	*first_epg_entry;
	zap2it_single_epg_entry_s 	*current_epg_entry;
//	zap2it_single_epg_entry_s 	*fetch_epg_entry;
	struct 		_zap2it_epg_channel_s *next;
};
typedef struct _zap2it_epg_channel_s zap2it_epg_channel_s;


typedef struct {
	uint8_t cache;
	char cache_dir[FILENAME_MAX];
//	uint8_t force_update;
	uint8_t id;
	uint8_t die;
	uint8_t wait;
	uint8_t max_thread_count;
	pthread_t thread;
	uint64_t start_time;
	uint64_t last_update_time;
	uint64_t update_wait_time;
	uint32_t fetch_days;
	uint32_t fetch_count;
	char zap_lineup[24];
	char zap_zip[6];

	pthread_t update_thread;
	pthread_mutex_t update_lock;

	zap2it_epg_channel_s *first_channel;
	zap2it_epg_channel_s *current_channel;
	int (*cb_get_epg)(zap2it_single_epg_entry_s *);

} zap2it_epg_s;


void zap2it_free_epg_data(zap2it_epg_s *);
zap2it_epg_s * zap2it_epg_init(uint8_t, uint8_t);
TIMER_STRUCT * zap2it_get_epg(zap2it_epg_s *, uint64_t, uint64_t, uint64_t);
int64_t zap_get_start_time(time_t);
TIMER_STRUCT * zap2it_get_single_epg(zap2it_epg_s *, uint64_t, uint64_t, uint64_t);

#ifdef __cplusplus
    }
#endif


#endif

